{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 75\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please write a program to randomly print a integer number between 7 and 15 inclusive._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use random.randrange() to a random integer in a given range._**\n",
    "\n",
    "---\n",
    "\n",
    "**Solution:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "print(random.randrange(7, 16))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 76\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please write a program to compress and decompress the string \"hello world!hello world!hello world!hello world!\"._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use zlib.compress() and zlib.decompress() to compress and decompress a string._**\n",
    "\n",
    "---\n",
    "\n",
    "**Solution:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'x\\x9c\\xcbH\\xcd\\xc9\\xc9W(\\xcf/\\xcaIQ\\xcc \\x82\\r\\x00\\xbd[\\x11\\xf5'\n",
      "b'hello world!hello world!hello world!hello world!'\n"
     ]
    }
   ],
   "source": [
    "import zlib\n",
    "\n",
    "t = zlib.compress(b'hello world!hello world!hello world!hello world!')\n",
    "print(t)\n",
    "print(zlib.decompress(t))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 77\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please write a program to print the running time of execution of \"1+1\" for 100 times._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use timeit() function to measure the running time._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime\n",
    "\n",
    "before = datetime.datetime.now()\n",
    "for i in range(100):\n",
    "    x = 1 + 1\n",
    "after = datetime.datetime.now()\n",
    "execution_time = after - before\n",
    "print(execution_time.microseconds)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "\n",
    "before = time.time()\n",
    "for i in range(100):\n",
    "    x = 1 + 1\n",
    "after = time.time()\n",
    "execution_time = after - before\n",
    "print(execution_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 78\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please write a program to shuffle and print the list [3,6,7,8]._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use shuffle() function to shuffle a list._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "\n",
    "lst = [3, 6, 7, 8]\n",
    "random.shuffle(lst)\n",
    "print(lst)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "\n",
    "# shuffle with a chosen seed\n",
    "lst = [3, 6, 7, 8]\n",
    "seed = 7\n",
    "random.Random(seed).shuffle(lst)\n",
    "print(lst)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 79\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please write a program to generate all sentences where subject is in [\"I\", \"You\"] and verb is in [\"Play\", \"Love\"] and the object is in [\"Hockey\",\"Football\"]._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use list[index] notation to get a element from a list._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "subjects = [\"I\", \"You\"]\n",
    "verbs = [\"Play\", \"Love\"]\n",
    "objects = [\"Hockey\", \"Football\"]\n",
    "\n",
    "for sub in subjects:\n",
    "    for verb in verbs:\n",
    "        for obj in objects:\n",
    "            print(\"{} {} {}\".format(sub, verb, obj))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
